{
	template:`
	<a-page-header title="商品信息" >
		<template #extra>
		    <a-button v-if="oper=='edit'" type="primary" @click="saveGoods">保存</a-button>
			<m-back @click="back(false);">关闭</m-back>
		</template>
		<a-card :hoverable="true" :bodyStyle="{padding:0}">
			<a-descriptions :column="2" bordered class="index-descriptions" style="margin:-1px;">
				<a-descriptions-item label="性质" span="2">
				    <div class="padding-lr-sm">
                        <a-radio-group v-if="oper=='edit'&&!model.oid" v-model:value="model.property" :options="dictOptions('m.store.model.StoreGoods!property')" />
                        <a-tag v-else color="processing">{{dict('m.store.model.StoreGoods!property',model.property)}}</a-tag>
				    </div>
				</a-descriptions-item>
				<a-descriptions-item label="商品名称" span="2">
					<a-input v-if="oper=='edit'" v-model:value="model.name" />
					<div v-else>{{model.name}}</div>
				</a-descriptions-item>
				<a-descriptions-item label="商品类型">
					<a-input v-if="oper=='edit'" v-model:value="model.typeName" />
					<div v-else>{{model.typeName}}</div>
				</a-descriptions-item>
				<a-descriptions-item label="商品厂商">
					<a-input v-if="oper=='edit'" v-model:value="model.factoryName" />
					<div v-else>{{model.factoryName}}</div>
				</a-descriptions-item>
				<a-descriptions-item label="商品分类">
				    <a-select v-if="oper=='edit'" :options="dictOptions('m.store.model.StoreType:'+storeOid)" v-model:value="model.storeType.oid" show-search :filter-option="selectFilter"/>
					<div v-else>{{model.storeType.name}}</div>
				</a-descriptions-item>
				<a-descriptions-item label="报价">
					<a-input-number v-if="oper=='edit'" v-model:value="model.offerPrice" />
					<div v-else>{{model.offerPrice}}</div>
				</a-descriptions-item>
			</a-descriptions>
		</a-card>
	</a-page-header>
	<a-page-header title="商品详情" style="margin-top: -15px;">
	    <a-flex gap="middle" vertical>
            <a-card v-for="item in attrList" :hoverable="true" :bodyStyle="{padding:0}">
                <div class="padding">
                    <a-flex v-if="oper=='edit'" gap="small" align="center" justify="space-between">
                        <div><a-input v-model:value="item.groupName" placeholder="分组名称" style="width:480px;border:0;"/></div>
                        <a-space>
                            <a-button type="link" size="small" danger @click="delGroup(item.groupName)">删除</a-button>
                            <a-button type="link" size="small" @click="addAttr(item.groupName)">添加属性</a-button>
                        </a-space>
                    </a-flex>
                    <div v-else><b>{{item.groupName}}</b></div>
                </div>
                <a-descriptions column="3" bordered class="index-descriptions" style="margin:-1px;">
                    <a-descriptions-item v-for="(attr,idx) in item.attrs" span="3">
                        <template #label>
                            <a-input v-if="oper=='edit'" v-model:value="attr.name" placeholder="属性名称" class="text-right" style="width:140px;"/>
                            <div v-else>{{attr.name}}</div>
                        </template>
                        <div v-if="oper=='edit'">
                            <a-textarea v-model:value="attr.value" placeholder="属性值" auto-size style="width:450px;"/>
                            <a-button type="link" size="small" danger style="height:30px;" @click="delAttr(item.groupName,idx)"><m-icon name="icon-icon-57" size="16"></m-icon></a-button>
                        </div>
                        <div v-else><div v-for="t in attr.value.split('\\n')">{{t}}</div></div>
                    </a-descriptions-item>
                </a-descriptions>
            </a-card>
            <a-button v-if="oper=='edit'" type="primary" ghost @click="addGroup" block>添加属性分组</a-button>
	    </a-flex>
	</a-page-header>
	`,
	props: ['localeZh','param','parentVue'],
	data:function(){
		return {
		    model:{property:'A',storeType:{}},
		    attrList:[],
            oper:'',
            storeOid:''
		};
	},
	mounted(){
	    if(this.param.oper) this.oper=this.param.oper;
	    if(this.param.storeOid) this.storeOid=this.param.storeOid;
	    if(this.param.oid) this.loadModel(this.param.oid);
	},
	methods:{
	    loadModel:function(oid){
			this.requestData("action/store/storeGoods/get",
				{"oid":oid},
				function(json){
					if(json.code==0){
                        this.model=json.model;
                        this.attrList=JSON.parse(json.model.attrJson);
					}
				}.bind(this)
			);
	    },
	    saveGoods:function(){
	        this.model.attrJson=JSON.stringify(this.attrList);
			this.requestData("action/store/storeGoods/doSave",
				{"model":this.model},
				function(data){
					if(data.code==0){
                        this.remind().success(data.msg);
                        this.back(true);
					}else{
                        this.remind().error(data.msg);
					}
				}.bind(this)
			);
	    },
	    addGroup:function(){
            this.attrList.push({groupName:"",attrs:[]});
	    },
	    delGroup:function(groupName){
            for(let i=0;i<this.attrList.length;i++){
                if(this.attrList[i].groupName==groupName){
                    this.attrList.splice(i,1);
                    return;
                }
            }
	    },
	    addAttr:function(groupName){
	        if(groupName){
	            var idx=-1,num=0;
                for(let i=0;i<this.attrList.length;i++){
                    if(this.attrList[i].groupName==groupName){
                        idx=i;
                        num++;
                    }
                }
                if(num>1) this.remind().error("分组名称重复");
                else if(idx>=0) this.attrList[idx].attrs.push({name:"",value:""});
	        }else{
                this.remind().error("请输入分组名称再添加属性");
	        }
	    },
	    delAttr:function(groupName,idx){
            for(let i=0;i<this.attrList.length;i++){
                if(this.attrList[i].groupName==groupName){
                    this.attrList[i].attrs.splice(idx,1);
                    return;
                }
            }
	    }
	}
}